package com.cj.springmvc.test.task.springtemp;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;

import org.jboss.logging.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Component;

import com.cj.springmvc.test.bo.SendAlertBo;
import com.cj.springmvc.test.dto.PersonsDto;
/**
 * Spring-JmsTemplate，用于发送异步jms信息<br>
 * 另由于JmsTemplate的接收方法是同步接收的，<br>
 * 所以接收方法使用PDB，取代模板方法提供的recieve()
 * @author cj 
 * 
 */
@Component("sendAlertBo")
public class SendAlert implements SendAlertBo{
	private Logger log = Logger.getLogger(SendAlert.class);
	@Override
	public void sendAlert(final PersonsDto personsDto) {
		// we set the default destination in the example-jms.xml
		jmsTemplate.send(/*"persons.alert.queue",*/new MessageCreator() {
			
			@Override
			public Message createMessage(Session session) throws JMSException {
				log.info("==================>完成信息发送！");
				return session.createObjectMessage(personsDto);
			}
		});
	}
	
	@Autowired
	private JmsTemplate jmsTemplate;
}
